package com.atguigu.cloud.controller;

import com.atguigu.cloud.entities.Pay;
import com.atguigu.cloud.entities.PayDTO;
import com.atguigu.cloud.resp.ResultData;
import com.atguigu.cloud.service.PayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

/**
 * @author Kotori rotroutine@163.com
 * @since 2025/2/27
 */
@RestController
@RequestMapping("/pay")
@Tag(name = "支付微服务模块", description = "支付CRUD")
public class PayController {
    @Resource
    private PayService payService;
    @Value("${server.port}")
    private String port;

    @PostMapping("/add")
    @Operation(summary = "新增", description = "新增支付流水方法,json串做参数")
    public ResultData<Integer> addPay(@RequestBody PayDTO payDTO) {
        int rows = payService.add(new Pay(payDTO));
        return ResultData.success(rows);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除", description = "删除支付流水方法")
    public ResultData<Integer> deletePay(@PathVariable("id") Integer id) {
        int rows = payService.delete(id);
        return ResultData.success(rows);
    }

    @PutMapping("/update")
    @Operation(summary = "修改", description = "修改支付流水方法")
    public ResultData<Integer> updatePay(@RequestBody PayDTO payDTO) {
        Pay pay = new Pay(payDTO);
        int rows = payService.update(pay);
        return ResultData.success(rows);
    }

    @GetMapping("/get/{id}")
    @Operation(summary = "按照ID查流水", description = "查询支付流水方法")
    public ResultData<Pay> getPay(@PathVariable("id") Integer id) {
        Pay pay = payService.getById(id);
        return ResultData.success(pay);
    }

    @GetMapping("/getAll")
    @Operation(summary = "查询所有流水", description = "查询所有支付流水方法")
    public ResultData<List<Pay>> getAllPays() {
        List<Pay> pays = payService.getAll();
        return ResultData.success(pays);
    }

    // @GetMapping("/get/info")
    // public ResultData<String> getInfo(@Value("${kotoriforest.info}") String info, @Value("${spring.profiles.active}") String profile) {
    //     String msg = "port:" + port + ", info:" + info + ", profile:" + profile;
    //     return ResultData.success(msg);
    // }

    @GetMapping("/get/info")
    public String getInfo() {
        return "port:" + port + "\t" + UUID.randomUUID();
    }
}
